function! api#unite#init() abort
    if !exists("g:loaded_unite")
        try
            packadd unite.vim
        catch /.*/
            echoerr v:exception
        endtry
    endif
    if exists("g:loaded_unite") && g:loaded_unite
        let g:unite_keymap = s:unite_keymap()
        imap <c-f> <esc>:Unite ultisnips<cr>
        " space_keymap
        let g:space_keymap = get(g:, "space_keymap", { "name": "+space" })
        let g:space_keymap.u = g:unite_keymap
    endif
endfunction

function! s:unite_keymap() abort
    let g:unite_keymap = get(g:, "unite_keymap", {"name": "+unite"})
    " b
    let g:unite_bmap =  get(g:, "unite_bmap", { "name": "+buffer/bookmark" })
    let g:unite_bmap.b = [ ":Unite buffer",     "buffer" ]
    let g:unite_bmap.m = [ ":Unite bookmark",   "bookmark" ]
    let g:unite_bmap.t = [ ":Unite buffer_tab", "buffer_tab" ]
    let g:unite_keymap.b = g:unite_bmap
    " c
    let g:unite_cmap =  get(g:, "unite_cmap", { "name": "+change/command" })
    let g:unite_cmap.g = [ ":Unite change", "change" ] 
    let g:unite_cmap.c = [ ":Unite command", "command" ] 
    let g:unite_keymap.c = g:unite_cmap
    " d:
    let g:unite_directory_map = get(g:, "directory_map", { "name" : "+directory" })
    let g:unite_directory_map.a = [ ":Unite directory_rec/async", "async" ]
    let g:unite_directory_map.d = [ ":Unite directory", "directory" ] 
    let g:unite_directory_map.n = [ ":Unite directory/new", "new" ]
    let g:unite_directory_map.r = [ ":Unite directory_rec", "rec" ] 
    let g:unite_keymap.d = g:unite_directory_map 
    " f:
    let g:unite_file_map = get(g:, "unite_file_map", { "name": "+file/function"})
	let g:unite_file_map.f = [ ":Unite file", "file" ]
	let g:unite_file_map.a = [ ":Unite file/async", "async" ]
	let g:unite_file_map.n = [ ":Unite file/new", "new" ]
	let g:unite_file_map.l = [ ":Unite file_list", "list" ]
	let g:unite_file_map.p = [ ":Unite file_point", "point" ]
	let g:unite_file_map.r = [ ":Unite file_rec", "rec" ]
	let g:unite_file_map.A = [ ":Unite file_rec/async", "rec/async" ]
	let g:unite_file_map.g = [ ":Unite file_rec/git", "git" ]
	let g:unite_file_map.v = [ ":Unite file_rec/neovim", "neovim" ]
	let g:unite_file_map.F = [ ":Unite function", "function" ] 
	let g:unite_file_map["/"] = [ ":Unite find", "find" ]
    let g:unite_keymap.f = g:unite_file_map 
    " g:
    let g:unite_grep_map = get(g:, "unite_grep_map", { "name": "+grep" }) 
    let g:unite_grep_map.g = [ ":Unite grep", "grep" ]
    let g:unite_grep_map.G = [ ":Unite grep/git", "grep/git" ]
    let g:unite_keymap.g = g:unite_grep_map 
    " h:
    let g:unite_keymap.h = [ ":Unite history/unite", "history/unite" ]
    " j:
    let g:unite_jump_map = get(g:, "unite_jump_map", { "name": "+jump" }) 
    let g:unite_jump_map.j = [ ":Unite jump", "jump" ]
    let g:unite_jump_map.p = [ ":Unite jump_point", "jump_point" ]
    let g:unite_keymap.j = g:unite_jump_map 
    " l:
    let g:unite_lmap = get(g:, "unite_lmap", { "name": "+launcher/line" }) 
    let g:unite_lmap.a = [ ":Unite launcher", "launcher" ]
    let g:unite_lmap.l = [ ":Unite line", "line" ] 
    let g:unite_keymap.l = g:unite_lmap 
    " m:
    let g:unite_mmap = { "name": "+mapping/menu" }
    let g:unite_mmap.k = [ ":Unite mapping", "mapping" ]
    let g:unite_mmap.l = [ ":Unite menu", "menu" ]
    let g:unite_keymap.m = g:unite_mmap 
    " o
    let g:unite_omap = get(g:, "unite_omap", { "name": "+output"})
    let g:unite_omap.o = [ ":Unite output", "output" ]
    let g:unite_omap.s = [ ":Unite output/shellcmd", "output/shellcmd" ]
    let g:unite_keymap.o = g:unite_omap 
    " O: outline
    let g:unite_keymap.O = [ ":Unite outline", "outline" ]
    " p
    let g:unite_keymap.p = [ ":Unite process", "process" ]
    " r
    let g:unite_rmap = get(g:, "unite_rmap", { "name": "+register/resume/runtimepath" })
    let g:unite_rmap.g = [ ":Unite register", "register" ]
    let g:unite_rmap.s = [ ":Unite resume", "resume" ]
    let g:unite_rmap.p = [ ":Unite runtimepath", "runtimepath" ]
    let g:unite_keymap.r = g:unite_rmap
    " s
    let g:unite_smap = get(g:, "unite_smap", { "name": "+script/source" }) 
    let g:unite_smap.s = [ ":Unite script", "script" ] 
    let g:unite_smap.l = [ ":Unite source", "self" ]
    let g:unite_keymap.s = g:unite_smap
    " t
    let g:unite_keymap.t = [ ":Unite tab", "tab" ]
    " u
    let g:unite_keymap.u = [ ":Unite ultisnips", "ultisnips" ] 
    " v
    let g:unite_keymap.v = [ ":Unite vimgrep", "vimgrep" ]
    " w
    let g:unite_keymap.w = [ ":Unite window", "window" ]
    return g:unite_keymap
endfunction 
